package com.algrithom.quene;

import java.util.ArrayList;
import java.util.List;

public class CircleQueue2 {
    
    private final List<Integer> queue;
    
    private final int len;
    
    /**
     * Initialize your data structure here. Set the size of the queue to be k.
     */
    public CircleQueue2(int k){
        queue = new ArrayList<>(k);
        len = k;
    }
    
    /**
     * Insert an element into the circular queue. Return true if the operation is successful.
     */
    public boolean enQueue(int value){
        if (isFull()) {
            return Boolean.FALSE;
        }
        queue.add(value);
        return Boolean.TRUE;
    }
    
    /**
     * Delete an element from the circular queue. Return true if the operation is successful.
     */
    public boolean deQueue(){
        if (isEmpty()) {
            return Boolean.FALSE;
        }
        queue.remove(0);
        return Boolean.TRUE;
    }
    
    /**
     * Get the front item from the queue.
     */
    public int front(){
        if (isEmpty()) {
            return -1;
        }
        return queue.get(0);
    }
    
    /**
     * Get the last item from the queue.
     */
    public int rear(){
        if (isEmpty()) {
            return -1;
        }
        return queue.get(queue.size() - 1);
    }
    
    /**
     * Checks whether the circular queue is empty or not.
     */
    public boolean isEmpty(){
        if (queue.size() == 0) {
            return Boolean.TRUE;
        } else {
            return Boolean.FALSE;
        }
    }
    
    /**
     * Checks whether the circular queue is full or not.
     */
    public boolean isFull(){
        if (queue.size() == len) {
            return Boolean.TRUE;
        } else {
            return Boolean.FALSE;
        }
    }
}
